
import 'package:html/parser.dart';
import 'package:html/dom.dart';
import 'package:flutter_book/util/extensions/string_extensions.dart';

class AnalyzeHtmlUtil{
  static AnalyzeHtmlUtil? _htmlUtil;
  static AnalyzeHtmlUtil init(){
    if(_htmlUtil==null){
      _htmlUtil=AnalyzeHtmlUtil();
    }
    return _htmlUtil!;
  }


  getMenuUrlList(String html){
    var document=parse(html);
    List<Element> elements=document.body?.getElementsByTagName("li")??[];
    "资源可能有几个：${elements.length}".print;
    for (var value in elements) {
      var xing_vb4=value.getElementsByClassName("xing_vb4");
      if(xing_vb4.length<1){
        continue;
      }
      "名字：${xing_vb4[0].text}".print;
      "url：${xing_vb4[0].firstChild?.attributes["href"]}".print;
      var xing_vb5=value.getElementsByClassName("xing_vb5");
      if(xing_vb5.length>0){
        "类型：${xing_vb5[0].text}".print;
      }
      var xing_vb6=value.getElementsByClassName("xing_vb6");
      if(xing_vb6.length>0){
        "时间：${xing_vb6[0].text}".print;
      }
    }

  }

}